/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cz.uhk.ppro.traveler.entity;

import java.io.Serializable;
import java.sql.Date;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Transient;

/**
 *
 * @author dusi
 */
@Entity
public class TTrip implements Serializable, Comparable<TTrip> {
    
    private static final long serialVersionUID = 1L;
    
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private String destination;
    private float price;
    private int priority;       // 1 - highest | 5 - lowest
    private int type;           // 0 - draft| 1 - scheduled
    private Date startDate;
    private Date endDate;
    private float extraExpenses;
    @Transient
    private int remaining;

    // Relationships
    @ManyToOne
    private TUser user;

    // Constructors
    public TTrip() {

        this.price = 0;
        this.priority = 5;
        this.type = 0;
    }

    public TTrip(String destination, float price, int priority, TUser user) {

        this.destination = destination;
        this.price = price;
        this.priority = priority;
        this.user = user;
    }
    
    // Actions
    @Override
    public int compareTo(TTrip o) {
        
        if(this.priority < o.getPriority()){
            
            return -1;
        }
                
        else return 1;
    }

    // Accessors
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getDestination() {
        return destination;
    }

    public void setDestination(String destination) {
        this.destination = destination;
    }

    public float getPrice() {
        return price;
    }

    public void setPrice(float price) {
        this.price = price;
    }

    public int getPriority() {
        return priority;
    }

    public void setPriority(int priority) {
        this.priority = priority;
    }

    public TUser getUser() {
        return user;
    }

    public void setUser(TUser user) {
        this.user = user;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public Date getStartDate() {
        return startDate;
    }

    public void setStartDate(Date startDate) {
        this.startDate = startDate;
    }

    public Date getEndDate() {
        return endDate;
    }

    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }

    public float getExtraExpenses() {
        return extraExpenses;
    }

    public void setExtraExpenses(float extraExpenses) {
        this.extraExpenses = extraExpenses;
    }

    public int getRemaining() {
        return remaining;
    }

    public void setRemaining(int remaining) {
        this.remaining = remaining;
    }
    
    
    // General

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof TTrip)) {
            return false;
        }
        TTrip other = (TTrip) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "cz.uhk.ppro.traveler.entity.TTrip[id=" + id + "]";
    }

}
